package com.fund.com.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fund.com.base.BaseController;
import com.fund.com.entity.TComment;
import com.fund.com.service.TCommentService;
import com.fund.security.base.BaseAppController;
import com.fund.utils.AppResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论接口
 *
 * @author makejava
 * @since 2023-02-14 13:42:08
 */
@RestController
@RequestMapping("/tComment")
public class TCommentController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TCommentService tCommentService;

    /**
     * 分页查询所有数据
     *
     * @param page     分页对象
     * @param tComment 查询实体
     * @return 所有数据
     */
    @GetMapping("/page")
    public AppResponse<Page<TComment>> selectAll(Page<TComment> page, TComment tComment) {
        return AppResponse.ok(this.tCommentService.getPage(page, tComment));
    }

    @GetMapping("/pageLike")
    public AppResponse<Page<TComment>> selectAllLike(Page<TComment> page, TComment tComment) {
        return AppResponse.ok(this.tCommentService.getPageLikeName(page, tComment));
    }

    /**
     * 查询所有
     *
     * @param tComment t身体记录
     * @return {@link AppResponse}<{@link List}<{@link TComment}>>
     */
    @GetMapping("/queryAll")
    public AppResponse<List<TComment>> queryAll(TComment tComment) {
        return AppResponse.ok(this.tCommentService.queryAll(tComment));
    }


    /**
     * 新增数据
     *
     * @param tComment 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public AppResponse<Boolean> insert(@RequestBody TComment tComment) {
        return AppResponse.ok(this.tCommentService.insertOne(tComment));
    }

    /**
     * 修改数据
     *
     * @param tComment 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public AppResponse<Boolean> update(@RequestBody TComment tComment) {
        return AppResponse.ok(this.tCommentService.updateOneById(tComment));
    }

    /**
     * 删除数据  直接?idList=1&idList=2  拼接式传参
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/deleteList")
    public AppResponse<Boolean> delete(@RequestParam("idList") List<String> idList) {
        return AppResponse.ok(this.tCommentService.deleteListByIds(idList));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public AppResponse<TComment> selectOne(@PathVariable String id) {
        return AppResponse.ok(this.tCommentService.getOneById(id));
    }
}

